﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Xc.Application;
using Xc.DataObjects;

namespace Permissions.Web.Controllers
{
    public class RoleController : BaseController
    {
        //
        // GET: /Role/
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetGridData()
        {
            RoleAppService service = new RoleAppService();
            var request = new JqGridRequest(HttpContext);
            var jqGrid = service.GetAllRole(request.PageIndex, request.PageSize);
            return this.Json(jqGrid);
        }

        
        public JsonResult GetSelectData()
        {
            RoleAppService service = new RoleAppService();
            var request = new JqGridRequest(HttpContext);
            var select = service.GetAllRole();
            return this.Json(select,JsonRequestBehavior.AllowGet);
        }

        public JsonResult Create(RoleDataObject entity)
        {
            var result = base.GetModelValidate(entity);
            if (result == null)
            {
                RoleAppService service = new RoleAppService();
                return this.Json(service.AddRole(entity));
            }
            return this.Json(result);
        }

        public JsonResult Update(RoleDataObject entity)
        {
            var result = base.GetModelValidate(entity);
            if (result == null)
            {
                RoleAppService service = new RoleAppService();
                return this.Json(service.UpdateRole(entity));
            }
            return this.Json(result);
        }

        public JsonResult Delete(RoleDataObject entity)
        {
            RoleAppService service = new RoleAppService();
            return this.Json(service.DeleteRole(entity));
        }

        public ActionResult Edit()
        {
            return View();
        }
    }
}